# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: Aaron Bull Schaefer <aaron@elasticdog.com>
# Contributor: Ron Huang <ronhuang+aur at gmail dot com>

pkgname=fcgiwrap
pkgver=1.1.0
pkgrel=8
pkgdesc='A simple server for running CGI applications over FastCGI.'
arch=('loong64' 'x86_64')
url='https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/'
license=('MIT')
depends=('fcgi' 'systemd')
source=("$pkgname-$pkgver.tar.gz::https://github.com/gnosek/fcgiwrap/archive/${pkgver}.tar.gz"
        'link-with-libsystemd-instead-of-libsystemd-daemon.patch'
        'dc0c3b14f0d7bb014a9a4c6c17eb55a123496365.patch'
        'LICENSE')
md5sums=('d14f56bda6758a6e02aa7b3fb125cbce'
         'b2428010802d80c577553ee8c0fd8d7a'
         '3d573f45fac637a1076388683bd0beaf'
         '5aee62c27b4308f25ab32f05da387366')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  # https://github.com/gnosek/fcgiwrap/pull/37
  patch -Np1 -i ../link-with-libsystemd-instead-of-libsystemd-daemon.patch

  # fix kill() parameters
  patch -Np1 -i ../dc0c3b14f0d7bb014a9a4c6c17eb55a123496365.patch

  autoreconf -vi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  # -Werror is not much fun in release builds
  CFLAGS+=' -Wno-error=implicit-fallthrough'

  # Here --sbindir is implicitly prefixed by /usr
  ./configure --prefix=/usr --mandir=/share/man --sbindir=/bin --with-systemd
  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  make DESTDIR="${pkgdir}" install
  install -Dm0644 ../LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
